<?php
namespace Admin\Controller;
use Think\Controller;
use Think\Image;
class TestController extends Controller {
	//商务列表
    public function index(){
        $domainName = 'chinaz.com';
        $keywords = '站长|站长之家';
        $url = C('rank')['url']; 
        $arr = array(
        	'key' =>  C('rank')['key'],
        	'domainName' =>  $domainName,
        	'keywords' =>  $keywords,
        	
        );
        // $return  = httpRequest($url,'post',$arr);
        $data = array(
        	// 'taskid' => json_decode($return,true)['TaskID'];
        	'taskid' => 'c31908df340349cf97c4ddd1',
        );
        $getApi = C('rank')['GetApi'];
        $result  = httpRequest($getApi,'post',$data);
        $datalist = json_decode($result,true)['Result']['Data'];

        foreach ($datalist as $k => $v) {
        	$rk = str_replace('-','',$v['Result']['Ranks'][0]['RankStr']);
        	$arr[] = array(
        		'keyword' => $v['Keyword'],
        		'Rank' => intval($rk)-10,
        		// 'Rank' => $rk,
        	);
        }

        var_dump($arr);exit;
    }



    //test
    public function test5()
    {
        $url = C('rank')['url'];
        $key = C('rank')['key'];
        $getApi = C('rank')['GetApi'];
    }

    public function test(){
    	$url = C('rank')['url'];
    	$key = C('rank')['key'];
    	$getApi = C('rank')['GetApi'];
    	// $q=1;
    	foreach ($url as $k => $v) {
    		$arr = array(
	        	'key' =>  $key,
	        	'domainName' =>  'chinaz.com',
	        	'keywords' =>  '站长|站长之家',
        	);
        	$data = array(
        		'taskid' => json_decode(httpRequest($v,'post',$arr),true)['TaskID'],
        	);

        	// $datalist = json_decode(httpRequest($getApi,'post',$data),true)['Result']['Data'];
        	// $arrs = [];
        	// foreach ($datalist as $ks => $vs) {
	        // 	$rk = str_replace('-','',$vs['Result']['Ranks'][0]['RankStr']);
	        // 	$arrs[] = array(
	        // 		'keyword' => $vs['Keyword'],
	        // 		'Rank' => intval($rk)-10,
	        // 	);
	        // }
	        $list[] = json_decode(httpRequest($v,'post',$arr),true)['TaskID'];
	        // $result[$q] = $arrs;
	    	// $q++;
    	}
        sleep(10);
    	$result = $this->test3($list);
    	// $result = $this->test3();
    	var_dump($result);exit;
    }


    public function test2(){
    	$getApi = C('rank')['GetApi'];
    	// $arr = array(
    	// 	'b2479c915e7e432eb2764dde',
    	// 	'4e813732bec649a39bae4813',
    	// 	'5869e4f4f6f74337bbac0421',
    	// 	'26ae79a8a2564bd9985d6045',
    	// 	'ce2e709bc5a34b8d917961d9',
    	// 	'2f94811d55704bf78f3a59e3',
    	// );

    	// $array = array(
    	// 	'c6fed8fe511245d6bc498def',
    	// 	'3985e06cba5c4419b126c091',
    	// 	'c74faf74adf84df7b20bb0ac',
    	// 	'00453395efc44b95a298c432',
    	// 	'b441ee6c01d342169fb30cbc',
    	// 	'7ce0a9538a524bdaa50dc9c1',
    	// );
    	$q=1;
    	
    	foreach ($arr as $key => $v) {
    		
    		$data = array(
        		'taskid' => $v,
        	);
    		$datalist = json_decode(httpRequest($getApi,'post',$data),true)['Result']['Data'];
    		// var_dump($datalist);
    		$arrs = [];
    		foreach ($datalist as $k => $v) {
	        	$rk = str_replace('-','',$v['Result']['Ranks'][0]['RankStr']);
	        	$arrs[] = array(
	        		'keyword' => $v['Keyword'],
	        		'Rank' => intval($rk)-10,
	        	);
	    	}
	    	$result[$q] = $arrs;
	    	$q++;
	    	
    	}
    	var_dump($result);
    	exit;
    }


     public function test3($arr){
     // public function test3(){
    	$getApi = C('rank')['GetApi'];
    	// $arr = array(
    	// 	'b2479c915e7e432eb2764dde',
    	// 	'4e813732bec649a39bae4813',
    	// 	'5869e4f4f6f74337bbac0421',
    	// 	'26ae79a8a2564bd9985d6045',
    	// 	'ce2e709bc5a34b8d917961d9',
    	// 	'2f94811d55704bf78f3a59e3',
    	// );

    	// $array = array(
    	// 	'c6fed8fe511245d6bc498def',
    	// 	'3985e06cba5c4419b126c091',
    	// 	'c74faf74adf84df7b20bb0ac',
    	// 	'00453395efc44b95a298c432',
    	// 	'b441ee6c01d342169fb30cbc',
    	// 	'7ce0a9538a524bdaa50dc9c1',
    	// );
    	$q=1;
    	
    	foreach ($arr as $key => $v) {
    		
    		$data = array(
        		'taskid' => $v,
        	);
    		$datalist = json_decode(httpRequest($getApi,'post',$data),true)['Result']['Data'];
    		// var_dump($datalist);
    		$arrs = [];
    		foreach ($datalist as $k => $v) {
	        	$rk = str_replace('-','',$v['Result']['Ranks'][0]['RankStr']);
	        	$arrs[] = array(
	        		'keyword' => $v['Keyword'],
	        		'Rank' => intval($rk)-10,
	        	);
	    	}
	    	$result[$q] = $arrs;
	    	$q++;
	    	
    	}
    	return $result;
    }


    




}